package Thread;

import java.util.Scanner;

public class Demo9 {
    private static Object locker=new Object();

    public static void main(String[] args) {
        Thread thread1=new Thread(()->{
            synchronized (locker){
                System.out.println("t1 wait 之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1 wait 之后");
            }
        });
        Thread thread2=new Thread(()->{
            synchronized (locker){
                System.out.println("t2 wait 之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t2 wait 之后");
            }
        });
        Thread thread3=new Thread(()->{
            synchronized (locker){
                System.out.println("t3 wait 之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t3 wait 之后");
            }
        });
        Thread thread4=new Thread(()->{
            Scanner scanner=new Scanner(System.in);
            scanner.nextLine();
            System.out.println("t4 notify 之前");
           synchronized (locker){
               locker.notifyAll();
           }
            System.out.println("t4 notify 之后");
        });
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
    }
}
